package sicau.car.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import lombok.extern.slf4j.Slf4j;
import sicau.car.result.R;

/**
 * @Author ITcz
 * @Data 2020-07-26 - 18:42
 */
@RestControllerAdvice
@Slf4j
public class ApiExceptionHandler {
    /**
    * 处理自定义接口异常
    * */
    @ExceptionHandler(ApiException.class)
    public R handlerApiException(ApiException e){
        R r = new R();
        r.put("code",e.getCode());
        r.put("msg",e.getMsg());
        return r;
    }

    @ExceptionHandler(Exception.class)
    public R handlerException(Exception e){
        log.error(e.getMessage(), e);
        return R.error();
    }
}
